<template>
	<view class="container">
		<view class="nav-box" :style="'padding-top:' + statusBarHeight + 'px'">
			<view class="nav-item df" :style="'width:100%;height:' + titleBarHeight + 'px'">
				<view class="nav-back df" @click="navBack">
					<image src="/static/img/z.png" style="width:34rpx;height:34rpx"></image>
				</view>
				<view class="nav-user df" :data-url="'user/details?id=' + info.user_id" @click="navigateToFun">
					<image class="nav-user-avatar" :src="info.user.avatar" mode="aspectFill"></image>
					<view>
						<view class="nav-user-name ohto">{{info.user.name}}</view>
						<view v-if="info.adds_name" class="nav-user-adds df" catchtap="openLocationClick">
							<image src="/static/img/wz.png"></image>
							<text>{{info.adds_name}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="content-box" :style="'margin-top:' + (statusBarHeight+titleBarHeight) + 'px;width:100%'">
			<block v-if="1 == info.type && info.img">
				<swiper class="swiper-box" :style="{height:info.img[swiperIdx].wide!=info.img[swiperIdx].high?(750*info.img[swiperIdx].high)/info.img[swiperIdx].wide +'rpx':'750rpx'}" circular @change="swiperChange">
					<swiper-item v-for="(v,idx) in info.img" :key="idx" class="swiper-item" :data-i="idx" @click="swiperClick">
						<lazy-load :src="v.url"></lazy-load>
					</swiper-item>
				</swiper>
				<view v-if="info.img.length > 1" class="current df" :style="'top:calc(' + (statusBarHeight + titleBarHeight) + 'px + 20rpx)'">{{swiperIdx + 1}}/{{info.img.length}}</view>
				<view class="indicator df">
					<block v-if="info.img.length > 1">
						<view
							v-for="(v,i) in info.img.length"
							:key="i"
							class="indicator-item"
							:style="{width:'calc(100% / '+info.img.length+' - 10rpx)',background:i<=swiperIdx?'rgba(255, 255, 255, .85)':'#ffffff60'}"></view>
					</block>
				</view>
			</block>
			<video
				v-if="2 == info.type"
				class="video-box"
				:src="info.video.url"
				:poster="info.video.cover"
				show-mute-btn="true"
				autoplay
				custom-cache="false"
			></video>
			<view v-if="3 == info.type" class="audio-box df" :style="'margin-top:calc(' + (statusBarHeight + titleBarHeight) + 'px + 30rpx)'">
				<image class="audio-bg" :src="info.audio.cover" mode="aspectFill"></image>
				<view class="audio-mb"></view>
				<view class="audio-left">
					<image class="audio-left" src="info.audio.cover" mode="aspectFill"></image>
					<image class="icon" src="/static/img/yw.png"></image>
				</view>
				<view style="width:calc(100% - 338rpx)">
					<view class="audio-t1">{{info.audio.name}}</view>
					<view class="audio-t2">{{info.audio.intro}}</view>
				</view>
				<view class="audio-play" @click="audioBgClick">
					<view v-if="bgAudioStatus" class="icon">
						<play color="#fff"></play>
					</view>
					<image v-else class="icon" src="/static/img/a.png"></image>
				</view>
			</view>
			<view class="info-box">
				<view class="info-content">
					<text user-select="true">{{info.content}}</text>
				</view>
				<view v-if="info.circle_name || info.order_id || info.activity_id" class="info-tag">
					<view v-if="info.circle_name" class="tag-item df" style="border-radius:40rpx" :data-url="'circle/details?id=' + info.circle_id" @click="navigateToFun">
						<image class="icon" style="border-radius:50%" :src="info.circle_avatar" mode="aspectFill"></image>
						<text>{{info.circle_name}}</text>
					</view>
					<view v-if="info.activity_id" class="tag-item df" :data-url="'activity/details?id=' + info.activity_id" @click="navigateToFun">
						<image class="icon" style="border-radius:4rpx;width:50rpx" mode="aspectFill" src="info.activity_img"></image>
						<text>{{info.activity_name}}</text>
					</view>
					<block v-if="info.order_id">
						<view v-for="(item,i) in info.goods" :key="i" class="tag-item df" :data-url="'goods/details?id=' + item.goods_id" @click="navigateToFun">
							<image class="icon" style="border-radius:4rpx" :src="item.product_img" mode="aspectFill"></image>
							<text>{{item.goods_name}}</text>
						</view>
					</block>
				</view>
				<view class="more df">
					<view class="more-left">{{info.create_time_text}} · {{info.province}} · 浏览 {{info.view}}</view>
					<image @click="morePopupClick(!0)" class="more-right" src="/static/img/gd.png"></image>
				</view>
			</view>
		</view>
		<view class="comment-box" id="commentId">
			<view class="comment-top df">
				<view class="top-title">{{info.comment_count ? "评论 " + info.comment_count : "暂无评论"}}</view>
				<view class="top-btn df">
					<view class="btn-active" :style="'left:' + (0 == ctype ? '6rpx' : '74rpx')"></view>
					<view class="btn-item" :style="'color:' + (ctype ? '#000' : '#999')" @click="commentClick(0)">默认</view>
					<view class="btn-item" :style="'color:' + (ctype ? '#000' : '#999')" @click="commentClick(1)">最新</view>
				</view>
			</view>
			<view v-if="isEmpty" class="empty-box df">
				<image src="/static/img/inset/comment.png" />
				<view class="e1">期待你的评论</view>
				<view class="e2">发条评论表达你的想法吧</view>
			</view>
			<block v-else>
				<view v-for="(item,p) in comment_arr" :key="p" class="comment-item df">
					<view class="comment-avatar" :data-url="'user/details?id=' + item.user.id" @click="navigateToFun">
						<lazy-load :src="item.user.avatar"></lazy-load>
					</view>
					<view class="comment-info">
						<view class="comment-info-top df" :data-url="'user/details?id=' + item.user.id" @click="navigateToFun">
							<view v-if="user_id == item.user.id" class="wo">我</view>
							<view v-else-if="info.user_id == item.user.id" class="zz">作者</view>
							{{item.user.name}}
						</view>
						<view
							:class="['comment-info-content', 1 != item.status && 'db']"
							@click="openComment"
							data-type="1"
							:data-uid="item.user.id"
							:data-cid="item.id"
							:data-name="item.user.name"
							:data-idx="p"
							data-i="-1"
						>
							<text user-select="true">{{item.content}}</text>
						</view>
						<view class="comment-info-bottom df">
							<text>{{item.create_time_str}} {{item.province}}</text>
							<view
								@click="openComment"
								data-type="1"
								:data-uid="item.user.id"
								:data-cid="item.id"
								:data-name="item.user.name"
								:data-idx="p"
								data-i="-1"
							>回复</view>
							<view v-if="user_id == item.user.id && item.status <= 1" @click="delComment" :data-id="item.id" :data-idx="p">删除</view>
						</view>
						<block v-if="item.list_count">
							<view v-for="(v,g) in item.list" :key="g" class="comment-item df">
								<view class="comment-avatar-z" :data-url="'user/details?id=' + v.user.id" @click="navigateToFun">
									<lazy-load :src="v.user.avatar"></lazy-load>
									</view>
									<view class="comment-info">
										<view class="comment-info-top df" :data-url="'user/details?id=' + v.user.id" @click="navigateToFun">
											<view v-if="user_id == v.user.id" class="wo">我</view>
											<view v-else-if="info.user_id == v.user.id" class="zz">作者</view>
											{{v.user.name}}
										</view>
										<view
											:class="['comment-info-content', 1 != v.status && 'db']"

										>
											<text user-select="true">{{v.content}}</text>
										</view>
										<view class="comment-info-bottom df">
											<text>{{v.create_time_str}} {{v.province}}</text>
											<!-- <view
												@click="openComment"
												data-type="1"
												:data-uid="v.user.id"
												:data-cid="itme.id"
												:data-name="v.user.name"
												:data-idx="p"
												data-i="-1"
											>回复</view> -->
											<view v-if="user_id == v.user.id && v.status <= 1" @click="delComment" :data-id="v.id" :data-idx="p">删除</view>
									</view>
								</view>
							</view>
						</block>
						<block v-if="item.list_count">
							<view v-if="item.list_count > item.list.length" class="unfold" :data-id="item.id" :data-idx="p" @click="sonComment">{{1 == a.sonPage ? "展开 " + (item.list_count - 4) + " 条回复" : "展开更多回复"}}</view>
						</block>
					</view>
				</view>
			</block>
			<uni-load-more :showText="false" v-if="'no-more' != loadStatus" :status="loadStatus"></uni-load-more>
			<view v-else class="no-more">- THE END -</view>
		</view>
		<view class="footer-box bUp">
			<view class="footer-item df">
				<view v-if="isUser" class="footer-means df" data-url="center/means" @click="navigateToFun">
					<text>完善账号资料后即可评论</text>
				</view>
				<view v-else class="footer-comment df"  :data-type="0" :data-idx="-1" :data-i="-1" @click="openComment">
					<image :src="user_avatar" mode="aspectFill"></image>
					<view class="ohto">{{comtext ? comtext : comtips}}</view>
				</view>
				<view class="df">
					<view class="footer-icon" :data-type="0" :data-idx="-1" :data-i="-1" @click="openComment">
						<image src="/static/img/pl.png"></image>
						<text>{{info.comment_count ? info.comment_count : ""}} 评论</text>
					</view>
					<view class="footer-icon" @click="likeDynamic">
						<image v-if="info.is_like" class="hi" src="/static/img/dz1.png"></image>
						<image v-else class="hi" src="/static/img/dz.png"></image>
						<text v-if="info.like_count < 10000">{{info.like_count ? info.like_count : ""}} 赞</text>
						<text v-else>{{info.like_count_str}} 赞</text>
					</view>
					<view class="footer-icon" @click="shareClick(!0)">
						<image src="/static/img/fx.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view v-if="isComment" class="popup-comment-mask" @click="closeComment"></view>
		<view v-if="isComment" class="popup-comment" :style="'bottom:' + keyboardHeight + 'px'">
			<view class="comment-textarea">
				<block v-if="isComment">
					<textarea 
					v-model="comtext" 
					@blur="isComment = !1"
					@focus="focusClick" 
					:focus="isFocus" 
					:placeholder="comtips" 
					:adjust-position="false"
					cursor-spacing="120" 
					:show-confirm-bar="false" 
					maxlength="2000" 
					auto-height></textarea>
				</block>
			</view>
			<image @click="confirmFun" class="send" :src="comtext.length ? '/static/img/fs1.png' : '/static/img/fs.png'"></image>
		</view>
		<uni-popup ref="sharePopup" type="center" :safe-area="false">
			<view class="share-popup">
				<image class="share-img" src="/static/img/inset/share.jpg"></image>
				<view class="share-tips">
					<text>点击页面右上角</text>
					<image src="/static/img/xcx.png"></image>
					<text style="margin-left:78rpx">即可转发给朋友、分享到朋友圈、复制链接分享等操作。</text>
				</view>
				<view class="share-btn" @click="shareClick(!1)">确认</view>
			</view>
		</uni-popup>
		
		<uni-popup ref="morePopup" type="bottom" :safe-area="false">
			<view class="more-popup">
				<view class="more-item df" @click="openMenuPopup">
					<text>举报</text>
					<image src="/static/img/setting/5.png"></image>
				</view>
				<view class="more-item df" v-if="info.user_id == user_id" :data-url="'dynamic/add?id='+info.id" @click="navigateToFun">
					<text>编辑</text>
					<image src="/static/img/bj.png"></image>
				</view>
				<view class="more-item df" v-if="info.user_id == user_id" @click="delDynamic">
					<text style="color:#FA5150">删除</text>
					<image src="/static/img/sc.png"></image>
				</view>
				<view class="more-item df" @click="closeMorePopup(!1)">
					<text style="color:#999">取消</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="menuPopup" type="bottom" :safe-area="false">
			<view class="more-popup">
				<view class="more-item df" v-for="(item,idx) in menu" :key="idx" @click="saveFeedback(item)" :data-ct="item" >
					<text>{{item}}</text>
				</view>
				<view class="more-tips">请保证举报的真实性，轻触上方原因即可完成举报</view>
				<view class="more-item df" @click="menuPopupClick(!1)">
					<text style="color:#999">取消</text>
				</view>
			</view>
		</uni-popup>
		<!-- Tips Box -->
		<uni-popup ref="tipsPopup" type="top" mask-background-color="rgba(0, 0, 0, 0)">
			<view class="tips-box df" :style="{marginTop: statusBarHeight+44+'px'}">
				<view class="tips-item">{{tips_title}}</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	const app = getApp();
	const api = require('@/config/api');
	const util = require('@/utils/util');
	const config = require('@/utils/config');
	export default {
		components: {},
		data() {
			return {
				isUser: !0,
				isThrottling: !0,
				isCommentPopup: !1,
				footerHeight: 0,
				keyboardHeight: 0,
				ctype: 0,
				pic_arr: [],
				statusBarHeight: app.globalData.statusBarHeight,
				titleBarHeight: app.globalData.titleBarHeight,
				emojiUrl: api.emojiUrl,
				insetUrl: api.insetUrl,
				user_id: 0,
				user_avatar: '',
				id: 0,
				emojiarr:['🤣','😃','😄','😋','😎','😍','😘','🙂','😪','😫','😴','😌','😛','😜','😝','🤑','😲','😤','😢','😭','😦','😧','😨','😩','🤯','😬','😰','🤬','😷','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','😺','😸','😹','😻','😼','😽','🙀','😿','😾','🌹','🥀'],
				info: {
					user: {
						name: '...'
					},
					content: '...',
					type: 1,
					img: [],
					topic:[],
				},
				swiperIdx: 0,
				isEmpty: false,
				comment_arr: [],
				c_idx: 0,
				c_i: 0,
				page: 1,
				son_page: 1,
				loadStatus: 'more',
				c_c_id: 0,
				c_u_id: 0,
				isComment: false,
				isFocus: false,
				comtips: '说点什么..',
				comtext: '',
				isEmoji: false,
				menu: uni.getStorageSync('config').lnk_jb,
				tips_title: '',
				config: uni.getStorageSync('config'),
			}
		},
		async onLoad(option) {
			uni.showShareMenu();
			await this.$onLaunched;
			let that = this;
			if (option.id) {
				that.id = option.id;
				that.userInfoHandle();
				that.dynamicDetails();
			} else {
				that.tips_title = '未找到动态或动态异常！';
				that.$refs.tipsPopup.open();
				setTimeout(function() {
					that.$refs.tipsPopup.close();
					that.navBack();
				}, 2000);
			}
		},
		onShow() {
			this.userInfoHandle();
		},
		methods: {
			//滚动到底部 加载评论
			commentReachBottom() {
				if(!this.isEmpty && this.comment_arr.length)
				{
					this.page = this.page + 1;
					this.loadStatus = "loading";
					this.dynamicComment();
				}
			},
			//加载用户信息
			userInfoHandle() {
				let user = uni.getStorageSync('user_info');

				this.user_avatar = user.avatar;
				this.user_id = user.id;
				this.user_name = user.name;
				this.isUser = !0;
				if(user.mobile) this.isUser = !1;
			},
			//分享按钮
			shareClick(e) {
			    if(!e){
					this.$refs.sharePopup.close();
				}else{
					this.$refs.sharePopup.open();
				}
			},
			morePopupClick(e) {
				if(!e) this.$refs.morePopup.close()
				else this.$refs.morePopup.open();
			},
			menuPopupClick(e) {
				if(!e){
					this.$refs.menuPopup.close();
				}else{
					this.$refs.menuPopup.open();
					this.$refs.morePopup.close();
				}
			},
			commentClick(e) {
				if(this.isThrottling){
					this.isThrottling = !1;
					this.comment_arr = [];
					this.ctype = e;
					this.page = 1;
					this.dynamicComment();
				}
			},
			focusClick(e) {
				this.isFocus = !0;
				this.keyboardHeight = e.detail.height;
			},
			commentPopupClick(e) {
				let that = this;
				if(that.isFocusPopup)
				{
					setTimeout(function () {
						that.isFocusPopup = !1;
					}, 500)
				}else{
					if(e){
						that.isCommentPopup = !0;
						that.$refs.commentPopup.open();
					}else{
						that.isCommentPopup = !1;
						that.$refs.commentPopup.close();
					}
				}
			},

			dynamicDetails() {
				let that = this;
				util.request(api.dynamicDetailsUrl, {
					id: that.id
				}).then(function(res) {
					let is_pop = false;
					if (res.code == 200) {
						if (res.data.status != 1 && that.user_id != res.data.user_id) {
							is_pop = true;
							that.tips_title = '未找到动态或动态异常！';
						} else {
							that.info = res.data;							
							that.dynamicComment();
						}
					} else if (res.error == 600502) {
						uni.redirectTo({
							url: '/pages/dynamic/rest?id=' + that.id + '&cid=' + res.data,
						});
					} else {
						is_pop = true;
						that.tips_title = res.msg;
					}
					if (is_pop) {
						that.$refs.tipsPopup.open();
						setTimeout(function() {
							that.$refs.tipsPopup.close();
							that.navBack();
						}, 2000);
					}
				});
			},
			dynamicComment() {
				let that = this;
				that.loadStatus = 'loading';
				that.isEmpty = false;
				util.request(api.dynamicCommentUrl, {
					id: that.id,
					page: that.page,
					ctype: that.ctype,
				}).then(function(res) {
					console.log(res);
					that.isThrottling = !0;
					if (res.data.data.length > 0) {
						that.comment_arr = that.comment_arr.concat(res.data.data);
						that.page = res.data.current_page;
						that.loadStatus = 'more';
					} else if (that.page == 1) {
						that.loadStatus = 'more';
						that.isEmpty = true;
					} else {
						that.loadStatus = 'no-more';
					}
				})
			},
			sonComment(e) {
				let that = this;
				let id = e.currentTarget.dataset.id;
				let idx = e.currentTarget.dataset.idx;
				that.son_page = that.son_page + 1;
				util.request(api.sonCommentUrl, {
					id: id,
					page: that.son_page,
				}).then(function(res) {
					let data = res.data;
					that.comment_arr[idx].list = that.comment_arr[idx].list.concat(data.data);
					that.son_page = data.current_page;
				})
			},
			openComment(e) {
				let data = e.currentTarget.dataset;
				let type = data.type;
				let uid = data.uid ? data.uid : 0;
				let cid = data.cid ? data.cid : 0;
				let name = data.name ? data.name : '';
				this.c_idx = data.idx ? data.idx : 0;
				this.c_i = data.i != -1 ? data.i : -1;
				this.isComment = true;
				this.isFocus = true;
				if (type == 1) {
					this.c_c_id = cid;
					this.c_u_id = uid;
					this.comtips = '回复：' + name;
				}
			},
			confirmFun(e) {
				util.userRefreshInfo();
				let that = this;
				let emoji = e.currentTarget.dataset.emoji;
				if (!that.comtext && !emoji) {
					that.tips_title = '你得说点什么才能评论呀';
					that.$refs.tipsPopup.open();
					setTimeout(function() {
						that.$refs.tipsPopup.close();
					}, 1500);
					return;
				}
				util.request(api.commentDynamicUrl, {
					id: that.info.id,
					duid: that.info.user_id,
					ct: that.comtext,
					emoji: emoji ? that.emojiUrl + emoji + '.png' : '',
					imgs: that.pic_arr,
					img: that.info.type == 1 ? that.info.img[0].url : that.info.type == 2 ? that.info.video.img :
						'',
					reply_comment_id: that.c_c_id,
					reply_user_id: that.c_u_id,
				}, 'POST').then(function(res) {
					that.tips_title = res.msg;
					if (res.code == 200) {
						if (that.c_idx == -1) {
							if (that.comment_arr.length <= 0) {
								that.isEmpty = false;
								that.comment_arr = [];
							}
							that.comment_arr.unshift(res.data);
						} else if (that.c_idx == 0) {
							if (that.comment_arr[that.c_idx].list_count <= 0) that.comment_arr[that.c_idx].list = [];
							that.comment_arr[that.c_idx].list.unshift(res.data);
							that.comment_arr[that.c_idx].list_count = that.comment_arr[that.c_idx].list_count + 1;
						} else if (that.c_idx >= 0) {
							if (that.comment_arr[that.c_idx].list_count <= 0) that.comment_arr[that.c_idx].list = [];
							that.comment_arr[that.c_idx].list.push(res.data);
							that.comment_arr[that.c_idx].list_count = that.comment_arr[that.c_idx].list_count + 1;
						}
						console.log(that);
						if (!emoji) that.comtext = '';
						that.c_c_id = 0;
						that.c_u_id = 0;
						that.comtips = '说点什么..';
					}
					that.$refs.tipsPopup.open();
					setTimeout(function() {
						that.$refs.tipsPopup.close();
					}, 1500);
					that.isComment = false;
				});
			},
			delComment(e) {
				let that = this;
				let data = e.currentTarget.dataset;
				let idx = data.idx;
				let i = data.i ? data.i : -1;
				uni.showModal({
					title: '确定要删除该评论吗？',
					success: function(res) {
						if (res.confirm) {
							that.tips_title = '操作成功，已删除评论';
							that.$refs.tipsPopup.open();
							setTimeout(function() {
								that.$refs.tipsPopup.close();
							}, 1500);
							if (i == -1) {
								that.comment_arr[idx].content = '（该评论已被删除）';
								that.comment_arr[idx].status = 3;
							} else {
								that.comment_arr[idx].list[i].content = '（该评论已被删除）';
								that.comment_arr[idx].list[i].status = 3;
							}
							util.request(api.delCommentUrl, {
								id: data.id,
							}, 'POST');
						}
					}
				});
			},
			likeDynamic() {
				let that = this;
				that.info.is_like = !that.info.is_like;
				if (that.info.is_like) that.info.like_count++;
				if (!that.info.is_like) that.info.like_count--;
				util.request(api.likeDynamicUrl, {
					id: that.info.id,
					duid: that.info.user_id,
					is_like: that.info.is_like,
					content: that.info.content,
					img: that.info.type == 1 ? that.info.img[0].url : that.info.type == 2 ? that.info.video.img :
						'',
				}, 'POST');
			},
			delDynamic() {
				let that = this;
				uni.showModal({
					content: '确认要删除这篇动态吗？',
					success: function(res) {
						if (res.confirm) {
							util.request(api.delDynamicUrl, {
								id: that.info.id
							}, "POST").then(function(res) {
								app.globalData.dw = 1;
								that.tips_title = res.msg;
								that.$refs.tipsPopup.open();
								setTimeout(function() {
									that.$refs.tipsPopup.close();
									that.navBack();
								}, 1500);
							});
						}
					}
				});
			},
			saveFeedback(item) {
				let that = this;
				let content = "原因：" + item + " - 动态ID：" + that.info.id;
				util.request(api.saveFeedbackUrl, {
					type: '动态举报',
					content: content,
					imgs: [],
				}, "POST").then(function(res) {
					that.tips_title = res.msg;
					that.$refs.tipsPopup.open();
					setTimeout(function() {
						that.$refs.tipsPopup.close();
					}, 1500);
					that.$refs.menuPopup.close();
				});
			},
			swiperClick(e) {
				let idx = e.currentTarget.dataset.i;
				let urls = [];
				for (let v of this.info.img) {
					urls.push(v.url);
				}
				uni.previewImage({
					current: idx,
					urls: urls,
				});
			},
			swiperClick2(e) {
				let idx = e.currentTarget.dataset.i;
				let img = e.currentTarget.dataset.k;
				let urls = [];
				for (let v of img) {
					urls.push(v.url);
				}
				uni.previewImage({
					current: idx,
					urls: urls,
				});
			},
			closeComment() {
				if (this.isComment) {
					this.isComment = false;
					this.isFocus = false;
					this.isEmoji = false;
					this.c_idx = 0;
					this.c_i = -1;
					this.c_c_id = 0;
					this.c_u_id = 0;
					this.comtips = '说点什么..';
				}
			},
			openCommentTextarea(event) {
				util.userRefreshInfo();
				//this.isEmoji = false;
				this.isFocus = true;
			},
			openCommentEmoji() {
				this.isComment = true;
				this.isFocus = true;
				this.isEmoji = true;
			},
			swiperChange(e) {
				this.swiperIdx = e.detail.current;
			},
			openLocationClick(e) {
				uni.openLocation({
					latitude: parseFloat(this.info.lat),
					longitude: parseFloat(this.info.lng),
					name: this.info.adds
				});
			},
			openMorePopup() {
				util.userRefreshInfo();
				this.$refs.morePopup.open();
			},
			closeMorePopup() {
				this.$refs.morePopup.close();
			},
			openMenuPopup() {
				this.$refs.menuPopup.open();
				this.$refs.morePopup.close();
			},
			navigateToFun(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: '/pages/' + url
				})
			},
			navBack() {
				let currentRoutes = getCurrentPages();
				if (currentRoutes.length > 1) {
					uni.navigateBack();
				} else {
					uni.switchTab({
						url: '/pages/tabbar/index'
					})
				}
			},
			onReachBottom() {
				if (!this.isEmpty && this.comment_arr.length) {
					this.page = this.page + 1;
					this.dynamicComment();
				}
			},
			addImg(type) {

				let that = this;
				let count = 20 - that.pic_arr.length;
				if (type == 2) {
					count = 1;
				}
				uni.chooseImage({
					count: count,
					success: (res) => {
						uni.showLoading({
							title: '上传中...',
							mask: true
						});
						var filePath = res.tempFilePaths;
						if (type == 1) {
							that.type = 1;
							that.getImageInfo(filePath).then(function(imgArr) {
								for (let i in imgArr) {
									util.lnkUploadFile(imgArr[i].url).then(function(fileImg) {
										console.log(fileImg);
										if(fileImg.error == 87014){
											uni.hideLoading();
											uni.showToast({
												title: '图片不合规',
												duration: 2000,
												icon: 'error'
											});
										}else{
											imgArr[i].url = fileImg.data.url;
											if (imgArr.length == parseInt(i) + 1) {
												that.pic_arr = that.pic_arr.concat(imgArr);
												uni.hideLoading();
											}
										}
									});
								}
							});
						} 
					},
					fail: (err) => {
						console.log('chooseImage fail', err)
					}
				})
			},
			delImg(idx) {
				this.pic_arr.splice(idx, 1);
				if (this.pic_arr.length <= 0) this.type = 0;
			},
			getImageInfo(imgs) {
				return new Promise(function(resolve, reject) {
					let imgArr = [];
					for (let v of imgs) {
						uni.getImageInfo({
							src: v,
							success: function(res) {
								let item = {};
								item.url = res.path;
								item.wide = res.width;
								item.high = res.height;
								imgArr.push(item);
								if (imgs.length == imgArr.length) {
									resolve(imgArr);
								}
							}
						});
					}
				});
			},
			topicClick(id) {
				uni.navigateTo({
					url: '/pages/topic/topic?id=' + id
				})
			},
		},
		onShareAppMessage: function(e) {
			return {
				title: this.info.content,
				imageUrl: this.info.type == 1 ? this.info.img[0].url : this.info.type == 2 ? this.info.video.img : '',
				path: '/pages/dynamic/details?id=' + this.id
			}
		},
		onShareTimeline(res) {
			return {
				title: this.info.content,
				imageUrl: this.info.type == 1 ? this.info.img[0].url : this.info.type == 2 ? this.info.video.img : '',
				path: '/pages/dynamic/details?id=' + this.id
			}
		},
	}
</script>

<style lang="scss">
	@import url("/static/css/note/details.css");
</style>